<?php
// +----------------------------------------------------------------------
// | Description: ${Time}
// +----------------------------------------------------------------------
// | Author: Annnle <annnle@qq.com>
// +----------------------------------------------------------------------
// | Copyright (c) 2018~2018 http://juxiaoba.com All rights reserved.
// +----------------------------------------------------------------------


use Apps\Common\Libs\Log;
use Apps\Common\Libs\RedisClient;
use Apps\Common\Models\Netcar\Driver;
use Apps\Common\Models\Netcar\Order;
use Phalcon\Cli\Task;

class GuangdongTask extends Task
{
    const URL = 'http://wycapi.gzjt.gov.cn/api/app/common/binapi';

    /**
     * @var Redis
     */
    protected $redis;

    const ORDER = [
        'DDFQ', 'DDCG', 'JSYXB', 'JSYSB', 'DDCX', 'DDWY'
    ];

    const OPERATION = [
        'YYCF', 'YYDD', 'YYZF', 'CLYYSX', 'CLYYXX'
    ];

    protected $ddfq = [
        "companyId" => "syjcx",
        "address" => "500100",
        "orderId" => "timely15359542160002",
        "departTime" => "20180903135656",
        "orderTime" => "20180903135656",
        "passengerPhone" => "15825918622",
        "passengerNote" => "师傅麻烦快点来接我，着急",
        "departure" => "渝中区两路口街道鹅岭正街113附13号鹅岭山庄(下徐家坡)",
        "depLongitude" => "106537218",
        "depLatitude" => "29548310",
        "destination" => "重庆北站",
        "destLongitude" => "106551201",
        "destLatitude" => "29609570",
        "encrypt" => "1",
        "fareType" => "syj2017090101",
        "orderSource" => "0",
        "psgName" => "15825918622",
        "psgGender" => "1",
        "psgTotal" => "1",
        "vehType" => "KC",
        "isReserve" => "0",
        "isVoice" => "0",
        "voiceUrl" => "",
        "preMile" => "14.92",
        "preTime" => "30",
        "preFare" => "40.4",
        "useTime" => "20180903135656",
        "useLocale" => "渝中区两路口街道鹅岭正街113附13号鹅岭山庄(下徐家坡)",
        "useLon" => "106537218",
        "useLat" => "29548310",
        "taxiTypeCode" => "1",
        "serviceTypeCode" => "即时单",
        "departCity" => "500100",
        "destCity" => "500100"
    ];

    protected $ddcg = [
        "companyId" => "syjcx",
        "address" => "500100",
        "orderId" => "timely15359542160002",
        "longitude" => "106537218",
        "latitude" => "29548310",
        "encrypt" => "1",
        "licenseId" => "51020219630827064x",
        "driverPhone" => "13650522350",
        "vehicleNo" => "渝AU212F",
        "plateColor" => "蓝色",
        "distributeTime" => "20180903135701",
        "orderTime" => "20180903135656",
        "carCertNo" => "500100025192",
        "driverName" => "李昌碧",
        "idNo" => "51020219630827064x",
        "driCertNo" => "51020219630827064x",
        "departCity" => "500100",
        "destCity" => "500100",
        "departLocale" => "渝中区两路口街道鹅岭正街113附13号鹅岭山庄(下徐家坡)",
        "departLocaleDetail" => "渝中区两路口街道鹅岭正街113附13号鹅岭山庄(下徐家坡)",
        "departLon" => "106537218",
        "departLat" => "29548310",
        "desLocale" => "重庆北站",
        "desLocaleDetail" => "重庆北站",
        "desLon" => "106551201",
        "desLat" => "29609570",
        "resStatus" => "已响应",
        "resTime" => "1"
    ];

    protected $yycf = [
        "companyId" => "syjcx",
        "orderId" => "timely15359542160002",
        "licenseId" => "51020219630827064x",
        "passengerPhone" => "15825918622",
        "fareType" => "syj2017090101",
        "vehicleNo" => "渝AU212F",
        "plateColor" => "蓝色",
        "depLongitude" => "106537218",
        "depLatitude" => "29548310",
        "encrypt" => "1",
        "depTime" => "20180903135712",
        "waitMile" => "0",
        "passengerWaitTime" => "12",
        "driveWaitTime" => "12",
        "address" => "500100",
        "driverName" => "李昌碧",
        "driverIDCard" => "51020219630827064x",
        "driverCertCard" => "51020219630827064x",
        "passengerName" => "15825918622",
        "passengerSex" => "1"
    ];

    protected $yydd = [
        "companyId" => "syjcx",
        "orderId" => "timely15360282160001",
        "destLongitude" => "106551201",
        "destLatitude" => "29609570",
        "encrypt" => "1",
        "destTime" => "20180904113833",
        "driveMile" => "14.92",
        "driveTime" => "1783",
        "address" => "500100",
        "driverName" => "李昌碧",
        "driverPhone" => "13650522350",
        "driverIDCard" => "51020219630827064x",
        "driverCertCard" => "51020219630827064x",
        "vehicleNo" => "渝AU212F",
        "depTime" => "20180904111726",
        "depLongitude" => "106537218",
        "depLatitude" => "29548310",
        "waitTime" => "11",
        "passengerName" => "",
        "passengerSex" => "",
        "passengerPhone" => "15825918622",
        "price" => "40.4"
    ];

    protected $yyzf = [
        "companyId" => "syjcx",
        "orderId" => "timely15360282160001",
        "onArea" => "500104",
        "driverName" => "李昌碧",
        "licenseId" => "51020219630827064x",
        "fareType" => "syj2017090101",
        "vehicleNo" => "渝AU212F",
        "plateColor" => "蓝色",
        "bookDepTime" => "20180904111726",
        "waitTime" => "11",
        "depLongitude" => "106537218",
        "depLatitude" => "29548310",
        "depArea" => "渝中区两路口街道鹅岭正街113附13号鹅岭山庄(下徐家坡)",
        "depTime" => "20180904111726",
        "destLongitude" => "106551201",
        "destLatitude" => "29609570",
        "destArea" => "重庆北站",
        "destTime" => "20180904113833",
        "bookModel" => "小型轿车",
        "model" => "小型轿车",
        "driveMile" => "10.3",
        "driveTime" => "440",
        "waitMile" => "0",
        "factPrice" => "29.8",
        "price" => "29.8",
        "cashPrice" => "29.8",
        "lineName" => "",
        "linePrice" => "",
        "posName" => "",
        "posPrice" => "0",
        "benfitPrice" => "0",
        "bookTip" => "0",
        "passengerTip" => "0",
        "peakUpPrice" => "0",
        "nightUpPrice" => "0",
        "farUpPrice" => "0",
        "otherUpPrice" => "0",
        "payState" => "1",
        "payTime" => "20180904113833",
        "orderMatchTime" => "20180904113833",
        "invoiceStatus" => "0",
        "driverIDCard" => "51020219630827064x",
        "driverCertCard" => "51020219630827064x",
        "callPrice" => "0",
        "fareRuleUrl" => "10元起步价，动态打折"
    ];

    protected $ckpj = [
        "companyId" => "syjcx",
        "orderId" => "timely15353448430001",
        "evaluateTime" => "20180829152840",
        "serviceScore" => "5",
        "driverScore" => "5",
        "vehicleScore" => "5",
        "detail" => "活地图",
        "photoDetail" => "",
        "supDetail" => "",
        "supTime" => "",
        "address" => "500100",
        "totalScore" => "90"
    ];

    protected $jsysb = [
        "companyId" => "syjcx",
        "address" => "500100",
        "identifier" => "91500112MA5U3W6J0L",
        "driverName" => "李昌碧",
        "driverIDCard" => "51020219630827064x",
        "driverCertCard" => "51020219630827064x",
        "driverPhone" => "13650522350",
        "vehicleNo" => "渝AU212F",
        "plateColor" => "蓝色",
        "brand" => "吉利",
        "onWorkTime" => "20180829152836"
    ];

    protected $jsyxb = [
        "companyId" => "syjcx",
        "address" => "500100",
        "identifier" => "91500112MA5U3W6J0L",
        "driverName" => "李昌碧",
        "driverIDCard" => "51020219630827064x",
        "driverCertCard" => "51020219630827064x",
        "driverPhone" => "13650522350",
        "vehicleNo" => "渝AU212F",
        "plateColor" => "蓝色",
        "onWorkTime" => "20180828193242",
        "offWorkTime" => "20180829152836",
        "driveCount" => "10",
        "driveMile" => "200",
        "driveTime" => "400",
        "price" => "1000",
        "factPrice" => "500"
    ];

    protected $clyysx = [
        "companyId" => "syjcx",
        "licenseId" => "51020219630827064x",
        "vehicleNo" => "渝AU212F",
        "plateColor" => "蓝色",
        "loginTime" => "20180829152840",
        "longitude" => "106536896",
        "latitude" => "29548723",
        "encrypt" => "1",
        "address" => "500100"
    ];

    protected $clyyxx = [
        "companyId" => "syjcx",
        "licenseId" => "51020219630827064x",
        "vehicleNo" => "渝AU212F",
        "plateColor" => "蓝色",
        "logoutTime" => "20180829152840",
        "longitude" => "106536896",
        "latitude" => "29548723",
        "encrypt" => "1",
        "address" => "500100"
    ];

    protected $ddcx = [
        "companyId" => "syjcx",
        "address" => "500100",
        "orderId" => "timely15353645310001",
        "orderTime" => "20180829152836",
        "cancelTime" => "20180829152836",
        "initiator" => "1",
        "cancelTypeCode" => "1",
        "cancelReason" => "其他"
    ];

    protected $ddwy = [
        "companyId" => "syjcx",
        "address" => "500100",
        "orderId" => "timely15320928215087",
        "orderTime" => "20180829152836",
        "driCertNo" => "51020219630827064x",
        "vehicleNo" => "渝AU212F",
        "breakPart" => "1",
        "breakReason" => "不想坐了",
        "psgTel" => "15985251372",
        "breakTime" => "20180829152836"
    ];

    protected $jsydw = [
        'companyId' => 'syjcx',
        'address' => '500100',
        'driverRegionCode' => '500100',
        'vehicleNo' => '',
        'plateColor' => '蓝色',
        'vehicleRegionCode' => '500100',
        'positionTime' => '',
        'longitude' => '',
        'latitude' => '',
        'speed' => '1',
        'direction' => '23',
        'elevation' => '101',
        'mileage' => '2',
        'encrypt' => '1',
        'warnStatus' => '',
        'vehStatus' => '',
        'bizStatus' => '3',//1：载客 2：接单 3：空驶 4：停运
        'orderId' => '',
        'driverName' => '',
        'driverId' => '',
        'driverCertCard' => '',
        'vehicleType' => '小轿车',
        'positionType' => 'AUTO',//SJSB:司机上班、SJXB:司机下班、CKSC:乘客上车、CKXC:乘客下车、AUTO:定时上传、DDPD:派单
        'validity' => '1',
    ];

    // 10个司机
    protected $driver = [
        ['licenseId' => '51020219630827064x', 'driverPhone' => '13650522350', 'vehicleNo' => '渝AU212F', 'driverName' => '李昌碧'],
        ['licenseId' => '510923198605151221', 'driverPhone' => '15723337725', 'vehicleNo' => '渝AB553S', 'driverName' => '廖禄强'],
        ['licenseId' => '510221196312112117', 'driverPhone' => '18602336938', 'vehicleNo' => '渝AV233T', 'driverName' => '余学中'],
        ['licenseId' => '510213196412134719', 'driverPhone' => '15823073335', 'vehicleNo' => '渝AB553R', 'driverName' => '吴家均'],
        ['licenseId' => '510226197008067995', 'driverPhone' => '18702378808', 'vehicleNo' => '渝AX713T', 'driverName' => '戴华明'],
        ['licenseId' => '510225197508156445', 'driverPhone' => '15086858756', 'vehicleNo' => '渝AY560X', 'driverName' => '余昭兰'],
        ['licenseId' => '513031197710176078', 'driverPhone' => '13983381668', 'vehicleNo' => '渝AK012Q', 'driverName' => '刘艳林'],
        ['licenseId' => '512923197905175751', 'driverPhone' => '15922956628', 'vehicleNo' => '渝AV710M', 'driverName' => '杨福建'],
        ['licenseId' => '50022119890130451X', 'driverPhone' => '15823671930', 'vehicleNo' => '渝AU258F', 'driverName' => '陈伟'],
        ['licenseId' => '510215197110036934', 'driverPhone' => '13368330822', 'vehicleNo' => '渝AQ793N', 'driverName' => '廖红']
    ];

    protected $realDriverIds = [
        1046,
        1026,
        1003,
        1004,
        1043,
        1054,
        1050,
        1045,
        1055,
        1056
    ];

    protected $driver_ti = [
        '17898670839', '13617641612', '15803059836', '18444444444', '13206141938', '13647639216', '15823429910', '15826041423', '17898670111', '17898670222'
//        '17898670839', '13617641612'
    ];

    public function initialize()
    {
        $this->redis = RedisClient::getInstance()->redisOtherMethods();
        $this->redis->select(7);
    }

    public function indexAction()
    {
//        echo '开始：';
//        $this->redis->del('guangzhou:order:list');
//        $this->redis->del('guangzhou:driver:list');
//        exit;//现在不推送
        $dir = APP_CACHE_PATH . 'guangdong';
        // 订单
        $lrange = $this->redis->lRange('guangzhou:order:list', 0, -1);
        // 司机
        $ldriver = $this->redis->lRange('guangzhou:driver:list', 0, -1);
        // 接单
        foreach ($lrange as $value) {
            $redis_del = $value;
            $order = json_decode($value, true);
            $orderId = $order['orderId'];
            $status = $order['status'];
            // 判断是否是结束订单
            if ($status == 'end') {
                $name = ['YYDD', 'YYZF', 'CKPJ', 'JSYDW'];
            } elseif ($status == 'cancel') {
                $name = ['DDCX', 'DDWY'];
            } elseif ($status == 'create') {
                $name = ['DDFQ', 'DDCG'];
            } else {
                $name = ['YYCF', 'JSYDW'];
            }
            $val = Order::query()->columns([
                'order_number',
                'pre_distance',
                'pre_time',
                'preprice',
                'charge_start_address',
                'order_start_address',
                'charge_end_address',
                'order_end_address',
                'start_point', // 开始经纬度
                'end_point', // 结束经纬度
                "date_format( order_create_time, '%Y%m%d%H%i%s') as order_time", // 下单时间
                "date_format( order_get_time, '%Y%m%d%H%i%s') as order_get_time", // 接单时间
                "date_format( start_time, '%Y%m%d%H%i%s') as start_time", // 上车时间
                "date_format( end_time, '%Y%m%d%H%i%s') as end_time", // 下车时间
                "date_format( order_pay_time, '%Y%m%d%H%i%s') as order_pay_time",  // 支付时间
                'passenger_phone', // 手机
                'start_coordinate', // 上车经纬度
                'driver.driver_phone',
                'driver.number_plate',
                'driver.driver_idcard',
                'CONCAT(driver.driver_surname,driver.driver_name) AS driver_name'
            ])
                ->leftJoin(Driver::class, "driver.driver_id = Apps\Common\Models\Netcar\Order.driver_id", 'driver')
                ->where("order_number = '$orderId'")->execute()->getFirst();

            // 如果不是这几个司机叫的单也删除
            if (!in_array($val['driver_phone'], $this->driver_ti)) {
                $this->redis->lRemove("guangzhou:order:list", $redis_del, 0);
                continue;
            }

            $DDFQ_LIST = [];
            $DDCG_LIST = [];
            $YYCF_LIST = [];
            $YYDD_LIST = [];
            $YYZF_LIST = [];
            $CKPJ_LIST = [];
            $DDCX_LIST = [];
            $DDWY_LIST = [];
            $JSYDW_LIST = [];
            $JSYDW_LIST_DDPD = [];

            $start_point = json_decode($val['start_point'], true);
            $end_point = json_decode($val['end_point'], true);
            // DDFQ 订单发起
            $this->ddfq['orderId'] = $val['order_number'];
            $this->ddfq['departTime'] = $val['order_time'];
            $this->ddfq['orderTime'] = $val['order_time'];
            $this->ddfq['passengerPhone'] = $val['passenger_phone'];
            $this->ddfq['departure'] = $val['order_start_address'];
            $this->ddfq['depLongitude'] = self::transform($start_point[0]);
            $this->ddfq['depLatitude'] = self::transform($start_point[1]);
            $this->ddfq['destination'] = $val['order_end_address'] ?? $val['charge_end_address'];
            $this->ddfq['destLongitude'] = self::transform($end_point[0]);
            $this->ddfq['destLatitude'] = self::transform($end_point[1]);
            $this->ddfq['psgName'] = $val['passenger_phone'];
            $this->ddfq['preMile'] = $val['pre_distance'];
            $this->ddfq['preFare'] = $val['preprice'];
            $this->ddfq['useTime'] = $val['order_time'];
            $this->ddfq['useLocale'] = $val['order_start_address'];
            $this->ddfq['useLon'] = self::transform($start_point[0]);
            $this->ddfq['useLat'] = self::transform($start_point[1]);
            $DDFQ_LIST[] = $this->ddfq;
            // 司机手机
            $driver_phone = $val["driver_phone"];
            // DDCG 订单接单成功
            $this->ddcg['orderId'] = $val['order_number'];
            $this->ddcg['longitude'] = self::transform($start_point[0]);
            $this->ddcg['latitude'] = self::transform($start_point[1]);
            $this->ddcg['distributeTime'] = date('YmdHis', strtotime($val['order_get_time']) + 1); // $val['order_get_time'];
            $this->ddcg['orderTime'] = $val['order_time'];
            $this->ddcg['departLocale'] = $val['order_start_address'];
            $this->ddcg['departLocaleDetail'] = $val['order_start_address'];
            $this->ddcg['departLon'] = self::transform($start_point[0]);
            $this->ddcg['departLat'] = self::transform($start_point[1]);
            $this->ddcg['desLocale'] = $val['order_end_address'] ?? $val['charge_end_address'];
            $this->ddcg['desLocaleDetail'] = $val['order_end_address'] ?? $val['charge_end_address'];
            $this->ddcg['desLon'] = self::transform($end_point[0]);
            $this->ddcg['desLat'] = self::transform($end_point[1]);
            if (($key = array_search($val["driver_phone"], $this->driver_ti)) !== false) {

                $this->ddcg['licenseId'] = $this->driver[$key]['licenseId'];
                $this->ddcg['idNo'] = $this->driver[$key]['licenseId'];
                $this->ddcg['driCertNo'] = $this->driver[$key]['licenseId'];
                $this->ddcg['driverPhone'] = $this->driver[$key]['driverPhone'];
                $this->ddcg['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->ddcg['driverName'] = $this->driver[$key]['driverName'];

                // 定位
                $this->jsydw['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->jsydw['driverName'] = $this->driver[$key]['driverName'];
                $this->jsydw['orderId'] = $val['order_number'];
                $this->jsydw['driverId'] = $this->realDriverIds[$key];
                $this->jsydw['driverCertCard'] = $this->driver[$key]['licenseId'];
                $this->jsydw['positionType'] = 'DDPD';
                $this->jsydw['bizStatus'] = '2';
                $this->jsydw['positionTime'] = date('YmdHis', strtotime($val['order_get_time']) + 1);
                $this->jsydw['longitude'] = self::transform($start_point[0]);
                $this->jsydw['latitude'] = self::transform($start_point[1]);
                $JSYDW_LIST_DDPD = $this->jsydw;

                if ($status == 'end') {
                    $this->jsydw['positionType'] = 'CKXC';
                    $this->jsydw['bizStatus'] = '3';
                    $this->jsydw['positionTime'] = $val['end_time'];
                    $this->jsydw['longitude'] = self::transform($end_point[0]);
                    $this->jsydw['latitude'] = self::transform($end_point[1]);
                } else {
                    $this->jsydw['positionType'] = 'CKSC';
                    $this->jsydw['bizStatus'] = '1';
                    $this->jsydw['positionTime'] = $val['start_time'];
                    $this->jsydw['longitude'] = self::transform($start_point[0]);
                    $this->jsydw['latitude'] = self::transform($start_point[1]);
                }

                $JSYDW_LIST[] = $this->jsydw;

                if ($status == 'start') {
                    array_push($JSYDW_LIST, $JSYDW_LIST_DDPD);
                }

            }
            $DDCG_LIST[] = $this->ddcg;
            // YYCF 运营出发
            $this->yycf['orderId'] = $val['order_number'];
            $this->yycf['passengerPhone'] = $val['passenger_phone'];
            $this->yycf['passengerName'] = $val['passenger_phone'];
            $this->yycf['depLongitude'] = self::transform($start_point[0]);
            $this->yycf['depLatitude'] = self::transform($start_point[1]);
            $this->yycf['depTime'] = $val['start_time'];
            $this->yycf['passengerWaitTime'] = strtotime($val['start_time']) - strtotime($val['order_time']);
            $this->yycf['driveWaitTime'] = strtotime($val['start_time']) - strtotime($val['order_time']);
            if (($key = array_search($val["driver_phone"], $this->driver_ti)) !== false) {
                $this->yycf['licenseId'] = $this->driver[$key]['licenseId'];
                $this->yycf['driverIDCard'] = $this->driver[$key]['licenseId'];
                $this->yycf['driverCertCard'] = $this->driver[$key]['licenseId'];
                $this->yycf['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->yycf['driverName'] = $this->driver[$key]['driverName'];
            }
            $YYCF_LIST[] = $this->yycf;
            // YYDD 运营到达
            $this->yydd['orderId'] = $val['order_number'];
            $this->yydd['destLongitude'] = self::transform($end_point[0]);
            $this->yydd['destLatitude'] = self::transform($end_point[1]);
            $this->yydd['destTime'] = $val['end_time'];
            $this->yydd['driveMile'] = $val['pre_distance'];
            $this->yydd['depTime'] = $val['start_time'];
            $this->yydd['depLongitude'] = self::transform($start_point[0]);
            $this->yydd['depLatitude'] = self::transform($start_point[1]);
            $this->yydd['passengerPhone'] = $val['passenger_phone'];
            $this->yydd['price'] = $val['preprice'];
            $this->yydd['waitTime'] = strtotime($val['start_time']) - strtotime($val['order_time']);
            $this->yydd['driveTime'] = strtotime($val['end_time']) - strtotime($val['start_time']);
            if (($key = array_search($val["driver_phone"], $this->driver_ti)) !== false) {
                $this->yydd['driverIDCard'] = $this->driver[$key]['licenseId'];
                $this->yydd['driverCertCard'] = $this->driver[$key]['licenseId'];
                $this->yydd['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->yydd['driverPhone'] = $this->driver[$key]['driverPhone'];
                $this->yydd['driverName'] = $this->driver[$key]['driverName'];
            }
            $YYDD_LIST[] = $this->yydd;
            // YYZF 运营支付
            $this->yyzf['orderId'] = $val['order_number'];
            $this->yyzf['bookDepTime'] = $val['start_time'];
            $this->yyzf['depTime'] = $val['start_time'];
            $this->yyzf['depLongitude'] = self::transform($start_point[0]);
            $this->yyzf['depLatitude'] = self::transform($start_point[1]);
            $this->yyzf['depArea'] = $val['order_start_address'];
            $this->yyzf['destLongitude'] = self::transform($end_point[0]);
            $this->yyzf['destLatitude'] = self::transform($end_point[1]);
            $this->yyzf['destArea'] = $val['order_end_address'] ?? $val['charge_end_address'];
            $this->yyzf['destTime'] = $val['end_time'];
            $this->yyzf['driveMile'] = $val['pre_distance'];
            $this->yyzf['driveTime'] = strtotime($val['end_time']) - strtotime($val['start_time']);
            $this->yyzf['factPrice'] = $val['preprice'];
            $this->yyzf['price'] = $val['preprice'];
            $this->yyzf['cashPrice'] = $val['preprice'];
            $this->yyzf['payTime'] = $val['end_time'];//date('YmdHis', strtotime($val['end_time']) - 3);
            $this->yyzf['orderMatchTime'] = $val['end_time'];
            if (($key = array_search($val["driver_phone"], $this->driver_ti)) !== false) {
                $this->yyzf['licenseId'] = $this->driver[$key]['licenseId'];
                $this->yyzf['driverIDCard'] = $this->driver[$key]['licenseId'];
                $this->yyzf['driverCertCard'] = $this->driver[$key]['licenseId'];
                $this->yyzf['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->yyzf['driverName'] = $this->driver[$key]['driverName'];
            }
            $YYZF_LIST[] = $this->yyzf;
            //  CKPJ 乘客评价
            $this->ckpj['orderId'] = $val['order_number'];
            $this->ckpj['evaluateTime'] = date('YmdHis', strtotime($val['end_time']) + 2);//$val['end_time'];
            $CKPJ_LIST[] = $this->ckpj;
            //  DDCX 订单撤销
            $this->ddcx['orderId'] = $val['order_number'];
            $this->ddcx['orderTime'] = $val['order_time'];
            $this->ddcx['cancelTime'] = $val['order_get_time'];
            $DDCX_LIST[] = $this->ddcx;
            //  DDWY 订单违约
            $this->ddwy['orderId'] = $val['order_number'];
            $this->ddwy['orderTime'] = $val['order_time'];
            if (($key = array_search($val["driver_phone"], $this->driver_ti)) !== false) {
                $this->ddwy['driCertNo'] = $this->driver[$key]['licenseId'];
                $this->ddwy['vehicleNo'] = $this->driver[$key]['vehicleNo'];
            }
            $this->ddwy['psgTel'] = $val['passenger_phone'];
            $this->ddwy['breakTime'] = $val['order_get_time'];
            $DDWY_LIST[] = $this->ddwy;

            if (is_dir($dir)) {
                // 开始写入文件
                foreach ($name as $v) {
                    if ($v == 'DDCG' || $v == 'YYZF' || $v == 'CKPJ' || $v == 'JSYDW') {
                        sleep(2);
                    }
                    $json = [];
                    if (in_array($v, self::ORDER)) {
                        $file_name = 'syjcx_ORDER_' . $v . '_REQ_' . date('YmdHisB') . '.json';
                    }
                    if (in_array($v, self::OPERATION)) {
                        $file_name = 'syjcx_OPERATION_' . $v . '_REQ_' . date('YmdHisB') . '.json';
                    }
                    // 评价
                    if ($v == 'CKPJ') {
                        $file_name = 'syjcx_EVALUATE_' . $v . '_REQ_' . date('YmdHisB') . '.json';
                    }
                    // 定位
                    if ($v == 'JSYDW') {
                        $file_name = 'syjcx_GPS_' . $v . '_REQ_' . date('YmdHisB') . '.json';
                    }
                    // 是否存在这个文件
                    if (isset($file_name)) {
                        switch ($v) {
                            case 'DDFQ' :
                                $json['items'] = $DDFQ_LIST;
                                break;
                            case 'DDCG' :
                                $json['items'] = $DDCG_LIST;
                                break;
                            case 'YYCF' :
                                $json['items'] = $YYCF_LIST;
                                break;
                            case 'YYDD' :
                                $json['items'] = $YYDD_LIST;
                                break;
                            case 'YYZF' :
                                $json['items'] = $YYZF_LIST;
                                break;
                            case 'CKPJ' :
                                $json['items'] = $CKPJ_LIST;
                                break;
                            case 'DDCX' :
                                $json['items'] = $DDCX_LIST;
                                break;
                            case 'DDWY' :
                                $json['items'] = $DDWY_LIST;
                                break;
                            case 'JSYDW' :
                                $json['items'] = $JSYDW_LIST;
                                break;
                        }

                        // 把数据存成文件
                        file_put_contents($dir . '/' . $file_name, json_encode($json, true));

                        // 请求
                        self::http($dir, $file_name, $driver_phone);
                    }
                }
                //  删除redis
                $this->redis->lRemove("guangzhou:order:list", $redis_del, 0);
            } else {
                mkdir($dir);
            }

            // 循环redis去的值结束 删除当前值
        }
        // 上下班
        $count = new Driver();
        $time = time();
        $day = date('Ymd', $time);
        // 上班下班 上线下线
        foreach ($ldriver as $value) {
            $redis_del = $value;
            $driver = json_decode($value, true);
            $dataTime = date('YmdHis', strtotime($driver['onlineTime']));
            $endTime = date('YmdHis', strtotime($driver['offlineTime']));
            $status = $driver['status'];
            $phone = $driver['driverPhone'];
            $point = $driver['point'];

            $JSYSB_LIST = [];
            $JSYXB_LIST = [];
            $CLYYSX_LIST = [];
            $CLYYXX_LIST = [];
            $JSYDW_LIST = [];
            if (($key = array_search($phone, $this->driver_ti)) !== false) {
                // 上班
                $this->jsysb['licenseId'] = $this->driver[$key]['licenseId'];
                $this->jsysb['driverIDCard'] = $this->driver[$key]['licenseId'];
                $this->jsysb['driverCertCard'] = $this->driver[$key]['licenseId'];
                $this->jsysb['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->jsysb['driverName'] = $this->driver[$key]['driverName'];
                $this->jsysb['driverPhone'] = $this->driver[$key]['driverPhone'];
                $this->jsysb['onWorkTime'] = $dataTime;
                $JSYSB_LIST[] = $this->jsysb;
                // 定位
                $this->jsydw['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->jsydw['positionTime'] = $dataTime;
                $this->jsydw['longitude'] = self::transform($point[0]);;
                $this->jsydw['latitude'] = self::transform($point[1]);
                $this->jsydw['driverName'] = $this->driver[$key]['driverName'];
                $this->jsydw['driverId'] = $this->realDriverIds[$key];
                $this->jsydw['driverCertCard'] = $this->driver[$key]['licenseId'];

                // 下班
                $this->jsyxb['driverName'] = $this->driver[$key]['driverName'];
                $this->jsyxb['driverIDCard'] = $this->driver[$key]['licenseId'];
                $this->jsyxb['driverCertCard'] = $this->driver[$key]['licenseId'];
                $this->jsyxb['driverPhone'] = $this->driver[$key]['driverPhone'];
                $this->jsyxb['vehicleNo'] = $this->driver[$key]['vehicleNo'];

                $money = $count->getOrderAmountByDay('', $time);
                $this->jsyxb['onWorkTime'] = $dataTime;
                $this->jsyxb['offWorkTime'] = $endTime;
                $this->jsyxb['driveCount'] = $count->getOrderCount('', date('Y-m-d 00:00:00', $time), date('Y-m-d 23:59:59', $time));
                $this->jsyxb['driveTime'] = self::findNum($count->getOrderTimesByDay('', $day));
                $this->jsyxb['price'] = $money;
                $this->jsyxb['factPrice'] = $money;
                $JSYXB_LIST[] = $this->jsyxb;
                // 上线
                $this->clyysx['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->clyysx['licenseId'] = $this->driver[$key]['licenseId'];
                $this->clyysx['loginTime'] = $dataTime;
                $this->clyysx['longitude'] = self::transform($point[0]);
                $this->clyysx['latitude'] = self::transform($point[1]);
                $CLYYSX_LIST[] = $this->clyysx;
                // 下线
                $this->clyyxx['licenseId'] = $this->driver[$key]['licenseId'];
                $this->clyyxx['vehicleNo'] = $this->driver[$key]['vehicleNo'];
                $this->clyyxx['logoutTime'] = $endTime;
                $this->clyyxx['longitude'] = self::transform($point[0]);
                $this->clyyxx['latitude'] = self::transform($point[1]);
                $CLYYXX_LIST[] = $this->clyyxx;

                if ($status == 'online') {
                    $name = ['JSYSB', 'CLYYSX', 'JSYDW'];
                    $this->jsydw['positionType'] = 'SJSB';
                    $this->jsydw['bizStatus'] = '3';
                } else {
                    $name = ['JSYXB', 'CLYYXX', 'JSYDW'];
                    $this->jsydw['positionType'] = 'SJXB';
                    $this->jsydw['bizStatus'] = '4';
                }
                // 定位
                $JSYDW_LIST[] = $this->jsydw;

                foreach ($name as $v) {
                    sleep(2);
                    $json = [];
                    if (in_array($v, self::ORDER)) {
                        $file_name = 'syjcx_ORDER_' . $v . '_REQ_' . date('YmdHisB') . '.json';
                    }
                    if (in_array($v, self::OPERATION)) {
                        $file_name = 'syjcx_OPERATION_' . $v . '_REQ_' . date('YmdHisB') . '.json';
                    }
                    // 定位
                    if ($v == 'JSYDW') {
                        $file_name = 'syjcx_GPS_' . $v . '_REQ_' . date('YmdHisB') . '.json';
                    }
                    if (isset($file_name)) {
                        switch ($v) {
                            case 'JSYSB' :
                                $json['items'] = $JSYSB_LIST;
                                break;
                            case 'CLYYSX' :
                                $json['items'] = $CLYYSX_LIST;
                                break;
                            case 'JSYXB' :
                                $json['items'] = $JSYXB_LIST;
                                break;
                            case 'CLYYXX' :
                                $json['items'] = $CLYYXX_LIST;
                                break;
                            case 'JSYDW' :
                                $json['items'] = $JSYDW_LIST;
                                break;
                        }

                        // 把数据存成文件
                        file_put_contents($dir . '/' . $file_name, json_encode($json, true));

                        // 请求
                        self::http($dir, $file_name, $phone);
                    }
                }
            }
            //  删除redis
            $this->redis->lRemove("guangzhou:driver:list", $redis_del, 0);

        }

    }

    public static function http($dir, $file_name, $driver_phone = '')
    {
        // 读取文件
        $files = realpath($dir . '/' . $file_name);
        // 获取返回信息
        $result = self::request($files);

        //  Log::info('guangdong', 'request', $result);

        if ($result) {
//            echo "请求：" . $file_name . PHP_EOL . $result . PHP_EOL;
            echo "----" . $file_name . PHP_EOL;
            // 写入日志文件
            $myfile = fopen($dir . '/guangdong' . date('Ymd') . '-' . $driver_phone . '.log', "a+") or die("Unable to open file!");
            $txt = "发送：" . $file_name . PHP_EOL . $result . PHP_EOL;
            fwrite($myfile, $txt);
            fclose($myfile);
        }
        // 删除文件
        unlink($files);
    }

    /**
     * 发送请求
     * @param $url
     * @param string $send_str
     * @param array $header_arr
     * @return mixed|string
     */
    public static function sendByAsync($url, $send_str = '', $header_arr = [])
    {

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => $send_str,
            CURLOPT_HTTPHEADER => $header_arr,
        ));
        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        if ($err) {
            return "cURL Error #:" . $err;
        } else {
            return $response;
        }
    }

    /**
     * 组装请求
     * @param $files
     * @return mixed|string
     */
    public static function request($files)
    {
        // 文件名称
        $file_name = basename($files);
        // 文件内容
        $content = file_get_contents($files);
        // 生成MD5序列，必须
        $md5 = md5_file($files);

        $header_arr = [
            'binfile-md5:  ' . $md5,
            'binfile-auth: 13YehO6WQOVHN3fY',
            'binfile-gzip: false',
            'Content-Type: multipart/form-data; boundary=syjcxguangdong'
        ];

        $sendStr = "--syjcxguangdong
Content-Disposition: form-data; name=\"binFile\"; filename=\"$file_name\"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary\r\n
$content
--syjcxguangdong
Content-Disposition: form-data; name=\"filename\"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit\r\n
$file_name\r\n
--syjcxguangdong--";

//        return $content;
        echo "发送请求时间：" . date('YmdHis');
        return self::sendByAsync(self::URL, $sendStr, $header_arr);
    }

    /**
     * 坐标经纬度转换
     * @param $coord
     * @return string
     */
    public static function transform($coord)
    {
        return bcmul(pow(10, 6), $coord, 0);
    }

    /**
     * 时间
     * @param string $str
     * @return float|int
     */
    public static function findNum($str = '')
    {
        try {
            $str = trim($str);
            if (preg_match_all('/\d+/', $str, $arr)) {
                if (isset($arr[0])) {
                    $h = $arr[0][0] * 60;
                    return $h + $arr[0][1];
                }
            }
            return 0;
        } catch (Exception $e) {
            return 0;
        }
    }
}